/* const bar = "123";
const obj = {
  foo: "foo",
  method: function () {
    // 传统方式
    console.log("first");
    console.log(this, "method");
  },
  bar,
  method1() {
    console.log("first1");
    console.log(this, "method1");
  },
  [Math.random()]: 123, // 计算属性名
};

console.log(obj);
obj.method();
obj.method1(); */

// ------------------------------------------------------

// 方法
// Object.assign
/* const source1 = {
  a: 123,
  b: 123,
};
const target = {
  a: 456,
  c: 456,
};
const result = Object.assign(target, source1);
console.log(result, target, source1);

function func(obj) {
  // obj.name = "func obj";
  // console.log(obj);
  // 只在函数中修改
  const funcObj = Object.assign({}, obj);
  funcObj.name = "func obj";
  console.log(funcObj);
}

const obj1 = { name: "global obj" };
func(obj1);
console.log(obj1); */

// ------------------------------------------------------

// Object.is: 在 === 基础上适配了-0，+0，NaN直接的比较
/* console.log(
  0 == false,
  0 === false,
  NaN === NaN,
  Object.is(+0, -0),
  Object.is(NaN, NaN)
); */

// ------------------------------------------------------
// Proxy
/* const person = {
  name: "zce",
  age: 20,
};

const personProxy = new Proxy(person, {
  get(target, property) {
    return property in target ? target[property] : "default";
  },
  set(target, property, value) {
    // console.log(target, property, value);
    if (property === "age") {
      if (!Number.isInteger(value)) {
        throw new TypeError(`${value} is not an int`);
      }
    }
    target[property] = value;
  },
  deleteProperty(target, property) {
    console.log(target, property);
    delete target[property];
  },
});

personProxy.gender = true;
personProxy.age = 1;
delete personProxy.age;
// console.log(personProxy); */

const list = [];
const listProxy = new Proxy(list, {
  set(target, property, value) {
    target[property] = value;
    return true; // 表示写入成功
  },
});

listProxy.push(100);
listProxy.push(200);
